package com.example.mobile2021606177cke0507;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class SupplierActivity extends AppCompatActivity {

    private RadioGroup radGupSupplierName;
    private RadioButton radBtnSupplier1;
    private RadioButton radBtnSupplier2;
    private RadioButton radBtnSupplier3;
    private RadioButton radBtnSupplier4;
    private TextView tvSupplierTitle;
    private Button btnSupplierSubmit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_supplier);

        initView();
        btnSupplierSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int radBtnId=radGupSupplierName.getCheckedRadioButtonId();
                if (radBtnId!=-1){
                    RadioButton radioButton=findViewById(radBtnId);
                    String supplierName=radioButton.getText().toString();
                    Intent intent=new Intent();
                    intent.putExtra("supplier",supplierName);
                    setResult(RESULT_OK,intent);
                    finish();
                }
            }
        });
    }

    private void initView() {
        radGupSupplierName = (RadioGroup) findViewById(R.id.radGupSupplierName);
        radBtnSupplier1 = (RadioButton) findViewById(R.id.radBtnSupplier1);
        radBtnSupplier2 = (RadioButton) findViewById(R.id.radBtnSupplier2);
        radBtnSupplier3 = (RadioButton) findViewById(R.id.radBtnSupplier3);
        radBtnSupplier4 = (RadioButton) findViewById(R.id.radBtnSupplier4);
        tvSupplierTitle = (TextView) findViewById(R.id.tvSupplierTitle);
        btnSupplierSubmit = (Button) findViewById(R.id.btnSupplierSubmit);
    }
}